<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Admin_Paymentgateways extends Admin_Controller {
	public function __construct()
	{
		parent::__construct();
		$this->lang->load('paymentgateway');
	}
	public function ajax_payment_gateway_get(){
		$paymentgatewayEntity =  new CI_Payment_gateway_entity();
		$paymentgateway = $paymentgatewayEntity->init('id',$_REQUEST['id']);
		echo json_encode($paymentgateway);
	}
	public function ajax_payment_gateway_list(){		
		$paymentgatewayEntity =  new CI_Payment_gateway_entity();
		$paymentgatewayList = $paymentgatewayEntity->getPaymentGatewayList();
		$data['paymentgatewayList'] = $paymentgatewayList;
		$this->load->view('admin/paymentgateways/index', $data);
	}
	public function ajax_payment_gateway_save(){
		$result = array();
		$paymentgatewayEntity =  new CI_Payment_gateway_entity();
		if($_REQUEST['paymentgateway'] == null || $_REQUEST['paymentgateway'] == ""){
			$result['result'] = false;
			$result['message'] = lang('escort_paymentgateway_require');
		}else{
			if($this->_check_payment_gateway(0, $_REQUEST['paymentgateway'])){
				$result['result'] = false;
				$result['message'] = lang('escort_paymentgateway_existed');
			}else{
				$paymentgatewayEntity->setGateway($_REQUEST['paymentgateway']);
				$id = $paymentgatewayEntity->save($paymentgatewayEntity);
				$result['result'] = true;
				$result['message'] =lang('escort_paymentgateway_save_success');
				$result['id'] =$id;
			}
		}
		echo json_encode($result);
	}
	public function ajax_payment_gateway_update(){
		$result = array();
		$paymentgatewayEntity =  new CI_Payment_gateway_entity();
		if($_REQUEST['paymentgateway'] == null || $_REQUEST['paymentgateway'] == ""){
			$result['result'] = false;
			$result['message'] = lang('escort_paymentgateway_require');
		}else{
			if($this->_check_payment_gateway($_REQUEST['id'], $_REQUEST['paymentgateway'])){
				$result['result'] = false;
				$result['message'] = lang('escort_paymentgateway_existed');
			}else{
				$paymentgatewayEntity->setGateway($_REQUEST['paymentgateway']);
				$paymentgatewayEntity->setId($_REQUEST['id']);
				$paymentgatewayEntity->update();
				$result['result'] = true;
				$result['message'] = lang('escort_paymentgateway_save_success');
			}
		}
		echo json_encode($result);
	}
	public function ajax_payment_gateway_delete(){
		$result = array();
		$paymentgatewayEntity =  new CI_Payment_gateway_entity();
		$paymentgatewayEntity->delete($_REQUEST['id']);
		$result['message'] = lang('escort_paymentgateway_delete_success');
		echo json_encode($result);
	}
	function _check_payment_gateway($id, $name){
		$ci = &get_instance();
		return $ci->payment_gateway_entity->checkExistedName($id, $name);
	}
}
?>